-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: add top-level melt function as method #15521
Conversation
How should this be tested? |
where
|
Copying an entire test case would cause a lot of duplication though. Since |
@ResidentMario yes you can simply replace them (though I would still add a single function to test the api (e.g. that pd.melt works) |
also add this to |
And and addition to |
you could put it in Enhancements |
Codecov Report
@@ Coverage Diff @@
## master #15521 +/- ##
==========================================
+ Coverage 90.97% 90.97% +<.01%
==========================================
Files 145 145
Lines 49483 49492 +9
==========================================
+ Hits 45015 45024 +9
Misses 4468 4468
Continue to review full report at Codecov.
|
gtm? |
doc/source/whatsnew/v0.20.0.txt
Outdated
@@ -160,6 +160,7 @@ Other enhancements | |||
- ``Series.sort_index`` accepts parameters ``kind`` and ``na_position`` (:issue:`13589`, :issue:`14444`) | |||
|
|||
- ``DataFrame`` has gained a ``nunique()`` method to count the distinct values over an axis (:issue:`14336`). | |||
- ``DataFrame`` has gained a ``melt()`` method for unpivoting from a wide to long format (:issue:`12640`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that this is the same as pd.melt
lgtm. @jorisvandenbossche |
Will take a look tomorrow! |
@jorisvandenbossche bump :) |
can you rebase, this looks good though (mainly to fix the whatsnew) |
Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few doc comments
@@ -105,7 +105,9 @@ | |||
optional_by=""" | |||
by : str or list of str | |||
Name or list of names which refer to the axis items.""", | |||
versionadded_to_excel='') | |||
versionadded_to_excel='', | |||
versionadded_melt='\n.. versionadded:: 0.20.0\n', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs extra spaces (you can check pd.DataFrame.melt?
if you are on this branch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by this, can you clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do pd.DataFrame.melt?
you see:
Signature: pd.DataFrame.melt(self, id_vars=None, value_vars=None, var_name=None, value_name='value', col_level=None)
Docstring:
"Unpivots" a DataFrame from wide format to long format, optionally leaving
identifier variables set.
This function is useful to massage a DataFrame into a format where one
or more columns are identifier variables (`id_vars`), while all other
columns, considered measured variables (`value_vars`), are "unpivoted" to
the row axis, leaving just two non-identifier columns, 'variable' and
'value'.
.. versionadded:: 0.20.0
Parameters
----------
....
so the versionadded is not indented as the other lines.
But I think Jeff fixed it before merging
@@ -265,7 +265,7 @@ the right thing: | |||
Reshaping by Melt | |||
----------------- | |||
|
|||
The :func:`~pandas.melt` function is useful to massage a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention here both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (GitHub is not folding this review component for some reason, however).
pandas/core/frame.py
Outdated
columns, considered measured variables (`value_vars`), are "unpivoted" to | ||
the row axis, leaving just two non-identifier columns, 'variable' and | ||
'value'. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This blank line can be removed
@ResidentMario Sorry my 'tomorrow' took a lot longer .. ! To be clear: I am in the meantime fully convinced of the usefulness of My main concern I have (or maybe not really concern, bur rather opportunity) is about the exact API. There have been raised some issues about this (#10109, #14876 (comment)), so I only think we should take this as an opportunity to look at the current For example, IMO it would be useful to make a comparison between the R If we don't find the time for this before 0.20 release, I am OK with merging this. |
ok @ResidentMario pls make those corrections and we can merge. If after this (in next week or two) we can figure out a better API we can discuss, otherwise can do it in next major version. Note that also like to incorporate (and deprecate) btw should also look at |
-1 on incoroporating |
I don't see this being done in the next two weeks however. |
not a problem |
thanks @ResidentMario I made the doc-string a tiny bit more flexible (so the examples are more clear), but great patch! |
(progress on?) API: add top-level functions as method #12640
tests added / passed
passes
git diff upstream/master | flake8 --diff
whatsnew entry
This is continued from PR#15513.